﻿//using Microsoft.EntityFrameworkCore;
//using Microsoft.EntityFrameworkCore.Storage;
//using Sgr.EntityFrameworkCore;
//using System.Data;
//using System.Data.Common;

//namespace Sgr.Data
//{
//    public sealed class EfcoreDbTransactionContext<TDbContext> : IDbTransactionContext where TDbContext : UnitOfWorkDbContext
//    {
//        private readonly IDbContextProvider<TDbContext> _dbContextProvider;

//        public EfcoreDbTransactionContext(IDbContextProvider<TDbContext> dbContextProvider)
//        {
//            _dbContextProvider = dbContextProvider ?? throw new ArgumentNullException(nameof(dbContextProvider));
//        }

//        /// <summary>
//        /// 数据库类型
//        /// </summary>
//        public async Task<DatabaseType> GetDatabaseTypeAsync()
//        {
//            return (await _dbContextProvider.GetDbContextAsync()).GetDatabaseType() ?? throw new NotSupportedException("无法识别的数据库类型。");
//        }

//        public async Task<DbConnection> GetDbConnectionAsync()
//        {
//            return (await _dbContextProvider.GetDbContextAsync()).Database.GetDbConnection();
//        }

//        public async Task<IDbTransaction?> GetDbTransactionAsync()
//        {
//            return (await _dbContextProvider.GetDbContextAsync()).Database.CurrentTransaction?.GetDbTransaction();
//        }
//    }
//}